
#include <scene/ShaderNode.h>
#include <base/d3d.h>
#include <base/resourcemanager.h>

ShaderNode::ShaderNode() {
  shader = -1;
  technique = -1;
}

ShaderNode::ShaderNode(const ShaderNode * rhs) {
  shader = rhs->shader;
  technique = rhs->technique;
}

long ShaderNode::preDraw(Device * device) {
  UINT cPasses;
  effect = ((Shader *)GetResource(shader))->getShader();
  ((Shader *)GetResource(shader))->setTechnique(technique);
  effect->Begin(&cPasses, 0);
  _passes = cPasses;

  return 0;
}

long ShaderNode::passDraw(Device * device, unsigned long pass) {
  effect->BeginPass(pass);
	effect->EndPass();
  return 0;
}

long ShaderNode::postDraw(Device * device) {
  effect->End();
  return 0;
}

SceneNode * ShaderNode::copy() const {
  return new ShaderNode(this);
}
